package middleware

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

const (
	DefaultUsername = "admin"
	DefaultPassword = "G(ZDr!TgIQI<(rAu"
)

func AuthMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		authHeader := c.GetHeader("Authorization")
		if authHeader == "" {
			c.JSON(http.StatusUnauthorized, gin.H{"error": "Authorization header required"})
			c.Abort()
			return
		}

		// 简单的认证检查，实际项目中应该使用JWT或其他更安全的方式
		if authHeader != "Bearer admin-token" {
			c.JSON(http.StatusUnauthorized, gin.H{"error": "Invalid token"})
			c.Abort()
			return
		}

		c.Next()
	}
}

func CheckCredentials(username, password string) bool {
	return username == DefaultUsername && password == DefaultPassword
}
